<script>
  $(document).ready(function() {
    $("#dtText2").datepicker(
		{
		   onSelect: function(dtText, inst) { 
				if(dtText.length>0){
					eventDate = dtText.split("/");
					newEventDate = eventDate[2]+'-'+eventDate[0]+'-'+eventDate[1];
					var url = "<?php echo $html->url(array('controller'=>'events','plugin'=>'events','action'=>'browse'))?>";		
					url += '/ByTime:'+newEventDate;
					window.location = url;
				}
		   }
		}
	);
  });
</script>

<?php $html->css('/events/css/events.css',null,array(),false);?>
<h2 class="fl">Events</h2>
<?php
//	<h2>Popular events this week</h2>
if($beingReloaded==0)
{
	if(isset($showAddButton) && ($showAddButton))
	{
		echo $html->link('<span>'.__('Add an Event').'</span>', array('controller'=>'events','plugin'=>'events','action'=>'add'),array('class'=>'button float_r','escape'=>false));
	}
}
?>
<div class="clear"></div>

<div class="noborder">
<div id="event_indexpopularblock">
	<?php
	if (!$beingReloaded) 
	{
		/*$reqData = $this->requestAction('events/populartw');
		$listEvents = $reqData[0];
		$view_type2 = $reqData[1];*/
	
		App::import('Model','Events.Event');
		$tempEvent = new Event();
		$listEvents = $tempEvent->getPopularThisWeek(4);
		if (!isset($view_type))
		{
			$view_type = "blog_view";
		}
		echo "<h2 class='module_title'>".__("Popular events this week")."</h2>";
		if(!empty($listEvents))
		{?>
		<div id="popular_ineventsindex">
			<?php echo $this->element('events', array('eventList' => $listEvents,'eventCallerName'=>'populartw2','view_type'=>$view_type,'loggedInUserId'=>$loggedInUserId));?>
		</div>
		<?php 
		}
		else
		{
			echo "<div class='no_results'>".__('No events found!')."</div>";
		}
	}
	?>
			<div class="clear"></div>

</div>
<div class="clear"></div>

<hr>
<div id="event_block">


<div>
<?php
if($beingReloaded==0){

	$listEvents2 = $tempEvent->getOtherPopularEvents(10);

	echo "<h2 class='module_title'>".__('Other popular events')."</h2>";
		echo $html->link(__('Browse all events'), array('controller'=>'events','plugin'=>'events','action'=>'browse'),array('class'=>'button'));

if(!empty($listEvents2))
	{
		echo "<ul class='filters_events'>";
		echo "<li>";
		echo __("See Events For").":";
		echo "</li><li>";
		echo $html->link(__('Today', true), array('controller'=>'events','plugin'=>'events','action'=>'browse','ByTime'=>'Today'));
		echo "</li><li>";
		echo $html->link(__('Tomorrow', true), array('controller'=>'events','plugin'=>'events','action'=>'browse','ByTime'=>'Tomorrow'));
		echo "</li><li>";
		echo $html->link(__('This Weekend', true), array('controller'=>'events','plugin'=>'events','action'=>'browse','ByTime'=>'This_Weekend'));
		echo "</li><li>";
		echo $html->link(__('This Week', true), array('controller'=>'events','plugin'=>'events','action'=>'browse','ByTime'=>'This_Week'));
		echo "</li><li>";
		echo $html->link(__('Next Week', true), array('controller'=>'events','plugin'=>'events','action'=>'browse','ByTime'=>'Next_Week'));
		echo "</li><li class='last'>";
		echo "<input type='label' value='".__("Jump to date")."' readonly='true' name = 'dtText2' id='dtText2'  onClick='$(this).datepicker().datepicker( \"show\" );' size='12' />";
		echo "</li></ul>"; ?>
		<hr>
	
	<div id="popular_ineventsindex2">
		<?php echo $this->element('events', array('eventList' => $listEvents2,'eventCallerName'=>'otherpopular2','view_type'=>$view_type,'loggedInUserId'=>$loggedInUserId));?>
	</div>
	<div class="clear"></div>
	<?php 
	}
	else
	{
		echo "<div class='no_results'>".__('No events found!')."</div>";
	}	
}
?>
</div>
<div class="clear"></div>

<?php
//unset is neccesary
unset($paginator->Html);
$paginator->Html = $appHtml;
?>

<?php
//$paginator->options(array('url'=>$this->getPagingUrl()));
	if($beingReloaded)
	{
		if(!empty($events))
		{?>
			<div class="user_actions">&nbsp;&nbsp;
				
				<span> <strong><?php echo __("Sort By")?> :</strong></span>
				<span><?php echo $paginator->sort(__('Recently added'),'created',array('url'=>array('direction'=>'desc')));?> | </span> 
				<span><?php echo $paginator->sort(__('Title'),'Event.title',array('url'=>array('direction'=>'both')));?> | </span> 
				<span><?php echo $paginator->sort(__('Free'),'Event.event_cost_to',array('url'=>array('direction'=>'asc')));?> | </span> 
				<span><?php echo $paginator->sort(__('Most Viewed'),'Event.view_count',array('url'=>array('direction'=>'desc')));?> | </span> 
				<span><?php echo $paginator->sort(__('Popular Events'),'(Event.soundscool_count+Event.whosin_count)',array('url'=>array('direction'=>'desc')));?></span>
			</div><br/>
			<!--
			<div class="user_actions">&nbsp;&nbsp;
				<?php //echo $this->element('event_sort_filter'); ?>
			</div><br/>
			-->
			<div id="eventsindex">
			<?php echo $this->element('events', array('eventList' => $events,'view_type'=>$view_type,'loggedInUserId'=>$loggedInUserId,'eventCallerName'=>'catwiseeventsresult'));?>
			</div>
			<div class='paginate'>
			<?php echo $paginator->prev(__('Prev'));?>
			<?php echo $paginator->numbers(array('separator'=>' '));?>
			<?php echo $paginator->next(__('Next'));?>
			</div>
			<div class="clear"></div>
			<?php 
		}
		else
		{
			echo "<div class='no_results'>".__('No events found!')."</div>";
		}
	}
	?>
</div>
	<div class="clear"></div>
	<?php 
		if ($beingReloaded == 0) {
			$events  = am($listEvents,$listEvents2);
		}
		if (!empty($events)) { 
		?>
		<div class="listing-view-map">
			<?php 
				//@GEOMAP INTERSECTION.
				//echo $this->element("event_view_map",array('showStreetView'=>true,'events'=>$events));?>
		</div>
	<?php } ?>
</div>

<script>
	function getCatEVents()
	{
		newCatId = document.getElementById('category').value;
		newDate = document.getElementById('dtText').value;
		newEventDate = '';
		if(newDate.length>0){
			eventDate = newDate.split("/");
			newEventDate = eventDate[2]+eventDate[0]+eventDate[1];
		}
		var url = "<?php echo $html->url(array('action'=>'index'))?>";		
		url += '/categoryId:'+newCatId+'/eventDate:'+newEventDate;
		$('#events_index').html('<img src="'+AJAX_LOADING_IMG+'"/>');
		$.get(url,function(html){ 
			$('#events_index').html(html);
		});
	}
</script>
